<?php

declare (strict_types=1);
namespace cms\system\model;

use Carbon\Carbon;
use Hyperf\ModelCache\Cacheable;
use HyperfExt\Auth\Authenticatable;
use HyperfExt\Auth\Contracts\AuthenticatableInterface;
use HyperfExt\Hashing\Hash;
use HyperfExt\Jwt\Contracts\JwtSubjectInterface;

/**
 * @property int $id 
 * @property string $username 用户昵称
 * @property string $password 用户密码
 * @property string $status 状态,1|正常、2|禁用
 * @property Carbon $created_at 创建时间
 * @property Carbon $updated_at 更新时间
 * @property Carbon $deleted_at 删除时间
 */
class AdminModel extends AbstractModel implements AuthenticatableInterface, JwtSubjectInterface
{
    use Authenticatable, Cacheable;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'admin';
    protected $fillable = ['username', 'password'];

    // region 处理用户密码 +++++
    public function setPasswordAttribute($value)
    {
        $this->attributes['password'] = Hash::make($value);
    }
    // endregion

    public function getJwtIdentifier()
    {
        // TODO: Implement getJwtIdentifier() method.
        return $this->getKey();
    }

    public function getJwtCustomClaims(): array
    {
        // TODO: Implement getJwtCustomClaims() method.
        return [
            'guard' => 'admin'    // 添加一个自定义载荷保存守护名称，方便后续判断
        ];
    }
}